//package Day14;
//
//import com.sun.imageio.plugins.common.ImageUtil;
//import org.jsoup.Jsoup;
//import org.jsoup.nodes.Document;
//import org.jsoup.nodes.Element;
//import org.jsoup.select.Elements;
//
//import javax.imageio.ImageIO;
//import javax.print.DocFlavor;
//import java.io.*;
//import java.net.MalformedURLException;
//import java.net.URL;
//import java.net.URLConnection;
//import java.util.HashSet;
//import java.util.List;
//import java.util.Set;
//
///**
// * @Author kalista
// * @Description 简单网络爬虫
// * @Date 2020/11/20  17:21
// **/
//public class Test07 {
//    public static void main(String[] args) {
//        InputStream in = null;
//        BufferedReader bufferedReader = null;
//        try {
//            URL url = new URL("https://www.umei.cc/p/gaoqing/cn/204293.htm");
//            in = url.openStream();
//            bufferedReader = new BufferedReader(new InputStreamReader(in));
//
//            StringBuilder sb = new StringBuilder();
//            /**
//             * 这样就可以将网络内容下载本地机器
//             * 然后进行数据分析。 建立索引。 也是 搜索引擎的第一步
//             */
//            String temp = "";
//            while (((temp = bufferedReader.readLine())) != null) {
//                sb.append(temp);
//            }
//            String html = sb.toString();
//            Document parse = Jsoup.parse(html);
//            Elements links = parse.body().select("img[src]");
//            List<String> src1 = links.eachAttr("src");
//            for (int i = 0; i < src1.size(); i++) {
//
//                downloadPicture(src1.get(i), i);
//            }
//
//
//            //输出到文件
////            FileOutputStream fileOutputStream = new FileOutputStream("f:\\tupian.txt");
////            for (String s : src1) {
////                fileOutputStream.write(s.getBytes());
////                fileOutputStream.write('\n');
////            }
////            fileOutputStream.close();
//
//
//        } catch (MalformedURLException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                in.close();
//                bufferedReader.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//    }
//
//
//    //链接url下载图片
//    private static void downloadPicture(String urlList, int i) throws IOException {
//        URL url = null;
//        try {
//            url = new URL(urlList);
//            DataInputStream dataInputStream = new DataInputStream(url.openStream());
//            String imageName = "f:\\"+i + ".jpg";
//            FileOutputStream fileOutputStream = new FileOutputStream(new File(imageName));
//
//            System.out.println(urlList);
//            byte[] buffer = new byte[1024];
//            int length;
//
//            while ((length = dataInputStream.read(buffer)) > 0) {
//                fileOutputStream.write(buffer, 0, length);
//            }
//            dataInputStream.close();
//            fileOutputStream.close();
//        } catch (MalformedURLException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}
